//
//  EJSShareView.m
//  EnjoyShoppingStreet
//
//  Created by lifayu on 2018/1/22.
//  Copyright © 2018年 lifayu. All rights reserved.
//

#import "EJSShareView.h"
#import "WXApi.h"
#import "WXApiObject.h"
#import "WechatAuthSDK.h"

@implementation EJSShareView

- (void)awakeFromNib{
    [super awakeFromNib];
    NSArray *imageArray = @[[UIImage imageNamed:@"social_icon"],[UIImage imageNamed:@"wechat_icon"]];
    for(int index = 0; index < _shareButtons.count; index ++){
        ImageTitleButton *button = _shareButtons[index];
        button.style = EImageTopTitleBottomCenter;
        button.padding = CGSizeMake(0, 10);
        [button setImage:imageArray[index] forState:UIControlStateNormal];
        button.imageSize = CGSizeMake(60, 60);
    }
}

- (IBAction)shareAction:(UIButton *)sender {
    NSInteger index = sender.tag - 100;
    
    WXMediaMessage *mediaMessage = [[WXMediaMessage alloc] init];
    mediaMessage.title = @"分享测试title";
    mediaMessage.description = @"分享测试描述";
    
    WXWebpageObject *extObj = [[WXWebpageObject alloc] init];
    extObj.webpageUrl = @"http://www.baidu.com";
    mediaMessage.mediaObject = extObj;
    
    
    SendMessageToWXReq *req = [SendMessageToWXReq new];
    req.bText = NO;
    req.message = mediaMessage;
    req.scene = WXSceneSession;
    if(index == 1){
        req.scene = WXSceneTimeline;
    }
    
    [WXApi sendReq:req completion:^(BOOL success) {
        
    }];
    [self cancelAction:nil];
}

- (IBAction)cancelAction:(id)sender {
    [UIView animateWithDuration:0.8 animations:^{
        self.contentViewBottom.constant = -213;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

+ (void)showInView:(UIView *)view{
    if(!view)
    {
        view = [UIApplication sharedApplication].keyWindow;
    }
    EJSShareView *shareView = [[UINib nibWithNibName:@"EJSShareView" bundle:nil] instantiateWithOwner:self options:nil].firstObject;
    shareView.frame = view.bounds;
    [view addSubview:shareView];
   
}


@end
